import request from '@/utils/request'

let VITE_APP_BASE_API = localStorage.getItem("local_server_ip") || window.HC_config.VITE_APP_BASE_API || process.env.VITE_APP_BASE_API;
const api = {
    basepath: '/gwfj/filedata'
}

export function deleteWordFile(id)
{
    return request({
        url: api.basepath + '/download/' + id,
        method: 'get'
    })
}

export function downWordFile(params)
{
    return request({
        url: api.basepath,
        method: 'delete',
        params
    })
}

export function getDownloadUrl(unid)
{
    return VITE_APP_BASE_API + api.basepath + '/download/' + unid
}

export function getZBDownloadUrl(unid)
{
    return VITE_APP_BASE_API + api.basepath + '/downloadZB/' + unid
}

export function getList(parameter)
{
    return request({
        url: api.basepath + '/list',
        method: 'get',
        params: parameter
    })
}

export function getInfo(unid)
{
    return request({
        url: api.basepath + '/' + unid,
        method: 'get'
    })
}

export function convertOFD(parentunid)
{
    return request({
        url: api.basepath + '/convertOFD/' + parentunid,
        method: 'get'
    })
}

// 上传正文
export function openUpload(parentunid, formData, callback)
{
    return request({
        url: api.basepath + '/upload/' + parentunid,
        method: 'post',
        data: formData,
        headers:{
            'Content-Type':'multipart/form-data'
        },
        timeout: 10000000,
        onUploadProgress(progressEvent)
        {
            if (progressEvent.lengthComputable)
            {
                const val = (progressEvent.loaded / progressEvent.total * 100).toFixed(0)
                var progress = parseInt(val)
                callback(progress)
            }
        }
    })
}